from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from time import sleep

driver = webdriver.Chrome()

driver.get("http://literallycanvas.com/")
driver.maximize_window()
sleep(2)

# 鼠标操作不是用坐标，（20,-20）表示横坐标加20，纵坐标减20
# canvas = driver.find_element(By.XPATH, '//*[@id="literally-canvas"]/div[3]/div[1]/canvas[2]')
# ActionChains(driver).click_and_hold(canvas).move_by_offset(0, 0).move_by_offset(0, 20)\
#     .move_by_offset(0, 20).move_by_offset(20, 0).release().perform()

jSScript = 'var element_canvas = document.getElementsByTagName("canvas")[0];'\
           + 'var cxt=element_canvas.getContext("2d");'\
           + 'cxt.fillStyle=\"#FFBB00\";' \
           + 'cxt.fillRect(50, 50, 170, 70);'
driver.execute_script(jSScript)

sleep(5)
driver.quit()
